home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / e / cha_source.lha / cha_source / oss_output.e < prev    next >
Encoding:
Text File  |  1999-12-18  |  1.8 KB  |  62 lines

  1. /*==========================================================================+
  2. | oss_output.e                                                              |
  3. | output buffer to write to OSS sample space                                |
  4. +--------------------------------------------------------------------------*/
  5.  
  6. OPT PREPROCESS
  7. OPT MODULE
  8.  
  9. MODULE '*outputbuffer', '*oss', '*oss_sample', '*word', '*debug'
  10.  
  11. /*-------------------------------------------------------------------------*/
  12.  
  13. EXPORT OBJECT oss_output OF outputbuffer
  14. PUBLIC
  15.     info   : PTR TO oss_sample
  16. PRIVATE
  17.     volume : LONG   -> output scaling factor
  18.     wptr   : LONG   -> current index
  19. ENDOBJECT
  20.  
  21. ->                             = 1.0
  22. PROC oss_output(sample, volume = $3F800000) OF oss_output HANDLE
  23.     self.outputbuffer()
  24.     NEW self.info.oss_sample(sample)
  25.     IF self.info.channels <> 1 THEN Throw("oss", 'only mono supported')
  26.     IF (self.info.type <> SAMPLETYPE_SAMPLE8) AND
  27.        (self.info.type <> SAMPLETYPE_SAMPLE16)
  28.         Throw("oss", 'only 8/16 bit samples supported')
  29.     ENDIF
  30.     self.volume := volume
  31. EXCEPT
  32.     self.end()
  33.     ReThrow()
  34. ENDPROC
  35.  
  36. PROC end() OF oss_output
  37.     END self.info
  38. ENDPROC SUPER self.end()
  39.  
  40. PROC write(float) OF oss_output
  41.     DEF byteptr : PTR TO CHAR, wordptr : PTR TO INT
  42.     debug(['write = \d (\z\h[8])', ! float * 100.0 !, float])
  43.     IF self.wptr < self.info.length
  44.         IF     self.info.bits =  8
  45.             byteptr := self.info.data
  46.             byteptr[self.wptr] := f2sbyte(! float * self.volume)
  47.         ELSE
  48.         ->ELSEIF self.bits = 16
  49.             wordptr := self.info.data
  50.             wordptr[self.wptr] := f2sword(! float * self.volume)
  51.         ENDIF
  52.         self.wptr := self.wptr + 1
  53.         RETURN TRUE
  54.     ELSE
  55.         RETURN FALSE
  56.     ENDIF
  57. ENDPROC
  58.  
  59. /*--------------------------------------------------------------------------+
  60. | END: oss_output.e                                                         |
  61. +==========================================================================*/
  62.